# Created by 黄景涛
# DATE: 2025/2/12
from datetime import datetime

""" 定制化的时间相关处理函数 """


def format_time(format_="%Y-%m-%d_%H%M%S"):
    """ 格式化当前时间 """
    now_time = datetime.now()
    return now_time.strftime(format_)


def get_timestamp(decimal: int = -1):
    """ 获取时间戳 """
    now = datetime.now().timestamp()

    if decimal == -1:
        return now

    t = str(now).split('.')
    if decimal:
        t[-1] = t[-1][:decimal]
        ans = float('.'.join(t))
    else:
        ans = int(t[0])

    return ans


if __name__ == '__main__':
    print(get_timestamp())
    print(get_timestamp(1))
    print(get_timestamp(0))